package m.common.model.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * 存放执行sql的语句和参数
 *
 */
public class QueryParameter {
	private String sql;
	private List<Object> valueList;
	public QueryParameter(String sql,List<Object> valueList){
		this.sql=sql;
		this.valueList=valueList;
	}
	public QueryParameter(String sql,Object[] values) {
		this.sql=sql;
		this.valueList= new ArrayList<>();
		this.valueList.addAll(Arrays.asList(values));
	}
	/**
	 * 获取排除order by 和limit的sql
	 * 
	 */
	public String getSubSql() {
		int i=this.sql.lastIndexOf(")");
		if(i<0) i=0;
		if(this.sql.lastIndexOf("ORDER BY")>=i) {
			return this.sql.substring(0, this.sql.lastIndexOf("ORDER BY"));
		}else if(this.sql.lastIndexOf("LIMIT")>=i) {
			return this.sql.substring(0, this.sql.lastIndexOf("LIMIT"));
		}
		return this.sql;
	}
	public List<Object> getValueList() {
		return valueList;
	}
	public void setValueList(List<Object> valueList) {
		this.valueList = valueList;
	}
	public String getSql() {
		return sql;
	}
	public void setSql(String sql) {
		this.sql = sql;
	}
}
